package br.perfiman.service.impl.patterns.strategy.brokerage;

import br.perfiman.model.Range;
import br.perfiman.model.Trade;

/**
 * Strategy to calculates the brokerages's value using ranged values to each order
 * 
 * @author Wagner Costa
 * @since 28/04/2008
 * @version 1.0
 *
 */
public class BrokerageRangeStrategy extends BrokerageStrategy{

	@Override
	public Double getBrokerage(Trade trade) {
		Double operationPrice = trade.getQuantity() * trade.getPrice();
		Double quote = null;
		for(Range range: trade.getBroker().getRanges()){
			if(operationPrice >= range.getInitialValue())
				quote = range.getQuote();
			else
				break;
		}
		return operationPrice * quote / 100;
	}

}
